package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.api.dao.ReceivingAddressMapper;
import com.qf.lanzhou.shop.api.service.ReceivingAddressService;
import com.qf.lanzhou.shop.pojo.entity.ReceivingAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jack
 */
@Service
public class ReceivingAddressServiceImpl implements ReceivingAddressService {

    @Autowired
    private ReceivingAddressMapper receivingAddressMapper;

    @Override
    public List<ReceivingAddress> getAddressByUserId(Long userId) {
        List<ReceivingAddress> list = receivingAddressMapper.selectAddress(userId);

        return list;
    }

    @Override
    public boolean addAddress(ReceivingAddress receivingAddress) {
        int i = receivingAddressMapper.insertAddress(receivingAddress);
        return checkSueeess(i);
    }

    private boolean checkSueeess(int i) {
        if (i == 1) {
            return false;
        }
        return true;
    }

    @Override
    public boolean delectAddress(Long userId) {
        int i = receivingAddressMapper.deleteAddressByUserId(userId);
        return checkSueeess(i);
    }

    @Override
    public boolean updateAddress(ReceivingAddress receivingAddress) {
        int i = receivingAddressMapper.updateAddress(receivingAddress);
        return checkSueeess(i);
    }

    @Override
    public boolean forOne(Long id) {
        int i = receivingAddressMapper.stateForOne(id);
        return checkSueeess(i);
    }

    @Override
    public boolean forZero(Long userId) {
        int i = receivingAddressMapper.stateForZero(userId);
        return checkSueeess(i);
    }

    @Override
    public ReceivingAddress getAddressById(Long id) {
        ReceivingAddress receivingAddress = receivingAddressMapper.selectByAddressId(id);
        return receivingAddress;
    }
}
